﻿#region LICENSE
// ------------------------------------------------------------------------------------------------------------------------------------
//    Project: https://code.google.com/p/comlib/
//    File: Helper.cs
//    Copyright (C) 2003 Sergy Laman and other authors

//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.

//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.

//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
// ------------------------------------------------------------------------------------------------------------------------------------
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QickSoft.Common
{
    /// <summary>
    /// Used as a general return where we need to return more than parameter
    /// </summary>
    public class Ret
    {
        public bool Success = false;
        public string Message = "";
        public object Data;
        public Ret()
        {
        }

        public Ret(bool success)
        {
            this.Success = success;
        }
        public Ret(bool success, object o)
        {
            this.Success = success;
            this.Data = o;
        }

        public Ret(bool success, string message)
        {
            this.Success = success;
            this.Message = message;
        }

        public Ret(bool success, string message, string message2)
        {
            this.Success = success;
            this.Message = message + "\r\n" + message2;
        }

        public Ret(bool success, string message, object o)
        {
            this.Success = success;
            this.Message = message;
            this.Data = o;
        }

        public Ret(string message)
        {
            this.Message = message;
        }

        public Ret(Exception ex)
        {
            this.Success = false;
            this.Message = ex.Message + "\r\n\r\nStack Trace:\r\n" + ex.ToString();
        }

        public static implicit operator bool(Ret r) { return r.Success; }
        public static implicit operator string(Ret r) { return r.Message; }

    }
}
